"""
商户配置相关服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.ledger.merchconf import (
    MerchRevUnbindRequest, MerchRevUnbindResponse,
    MerchFileUploadRequest, MerchFileUploadResponse,
    MerchIssueOpenRequest, MerchIssueOpenResponse,
    MerchIssueQueryRequest, MerchIssueQueryResponse,
    MerchIssueUpdateRequest, MerchIssueUpdateResponse,
    MerchRevSettleUpdateRequest, MerchRevSettleUpdateResponse,
    MerchRevBindQueryRequest, MerchRevBindQueryResponse,
    MerchRevBindRequest, MerchRevBindResponse,
    MerchRevQueryRequest, MerchRevQueryResponse,
    MerchRevOpenRequest, MerchRevOpenResponse
)


class MerchconfService(BaseService):
    """商户配置服务"""
    
    def __init__(self, config):
        """
        初始化商户配置服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的完整API路径
        api_url = getattr(request_class, 'API_URL', '')
        
        if not api_url:
            # 如果没有定义API_URL，使用默认路径
            return f"{base_url}/open/ledger/merchconf"
        
        # 直接返回完整路径
        return f"{base_url}{api_url}"
    
    def query_merch_rev(self, request):
        """
        查询商户分账信息
        
        Args:
            request: MerchRevQueryRequest实例
            
        Returns:
            MerchRevQueryResponse实例
        """
        return self.post(request, MerchRevQueryResponse)
    
    def unbind_merch_rev(self, request):
        """
        解绑商户分账
        
        Args:
            request: MerchRevUnbindRequest实例
            
        Returns:
            MerchRevUnbindResponse实例
        """
        return self.post(request, MerchRevUnbindResponse)
    
    def upload_merch_file(self, request):
        """
        上传商户文件
        
        Args:
            request: MerchFileUploadRequest实例
            
        Returns:
            MerchFileUploadResponse实例
        """
        return self.post(request, MerchFileUploadResponse)
    
    def open_merch_issue(self, request):
        """
        开通商户分账
        
        Args:
            request: MerchIssueOpenRequest实例
            
        Returns:
            MerchIssueOpenResponse实例
        """
        return self.post(request, MerchIssueOpenResponse)
    
    def query_merch_issue(self, request):
        """
        查询商户分账
        
        Args:
            request: MerchIssueQueryRequest实例
            
        Returns:
            MerchIssueQueryResponse实例
        """
        return self.post(request, MerchIssueQueryResponse)
    
    def update_merch_issue(self, request):
        """
        更新商户分账
        
        Args:
            request: MerchIssueUpdateRequest实例
            
        Returns:
            MerchIssueUpdateResponse实例
        """
        return self.post(request, MerchIssueUpdateResponse)
    
    def update_merch_rev_settle(self, request):
        """
        更新商户分账结算
        
        Args:
            request: MerchRevSettleUpdateRequest实例
            
        Returns:
            MerchRevSettleUpdateResponse实例
        """
        return self.post(request, MerchRevSettleUpdateResponse)
    
    def query_merch_rev_bind(self, request):
        """
        查询商户分账绑定
        
        Args:
            request: MerchRevBindQueryRequest实例
            
        Returns:
            MerchRevBindQueryResponse实例
        """
        return self.post(request, MerchRevBindQueryResponse)
    
    def bind_merch_rev(self, request):
        """
        绑定商户分账
        
        Args:
            request: MerchRevBindRequest实例
            
        Returns:
            MerchRevBindResponse实例
        """
        return self.post(request, MerchRevBindResponse)
    
    def open_merch_rev(self, request):
        """
        开通商户分账
        
        Args:
            request: MerchRevOpenRequest实例
            
        Returns:
            MerchRevOpenResponse实例
        """
        return self.post(request, MerchRevOpenResponse) 